package com.soft.small.app.service;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.soft.small.app.entity.AppClient;

public class AppHttpRequest {
    private AppClient appClient;
    public AppHttpRequest(AppClient appClient){
        this.appClient = appClient;
    }

    /**
     * 注册app获取si
     */
    public void register(){
        String method = "backdevice.si.register";
        String data = "{\"appDevice\":\"phone\",\"appImei\":\"1586951954.71262\",\"appMac\":\"F0:0F:EC:A7:E5:OP\",\"appModel\":\"Xiaomi:MI 6\",\"appPackage\":\"com.xxx\",\"appSys\":\"android\",\"appVer\":\"V5.01.001\",\"sysVer\":\"8.1.0\",\"resolvingPower\":\"1080*2340\"}";
        String result = appClient.getSmallHttp().requestPost(method,data,null);
        String si = JSONUtil.parseObj(result).getJSONObject("data").getStr("si");
        appClient.setSi(si);
    }

    /**
     * 验证码方式登录
     */
    public void appVerifyCodeLogin(){
        String method = "app.login.verifyCode";
        String data = "{\"appLanguage\":\"ZH_CN\",\"areaCode\":\"86\",\"username\":\"\",\"verifyCode\":\"000000\",\"si\":\"\",\"locations\":\"\",\"loginAddress\":\"\",\"oemFirm\":\"0X8001\",\"appModel\":\"android\"}";
        JSONObject dataJson = JSONUtil.parseObj(data);
        dataJson.put("username",appClient.getMobile());
        dataJson.put("si",appClient.getSi());
        String result = appClient.getSmallHttp().requestPost(method,dataJson.toString(),null);
        JSONObject respDataJson = JSONUtil.parseObj(result).getJSONObject("data");
        String userUnique = respDataJson.getStr("userUnique");
        String token = respDataJson.getStr("token");
        appClient.setUserUnique(userUnique);
        appClient.setToken(token);
    }

    /**
     * 获取家的列表
     */
    public void listHomeSn(){
        String method = "smallSmarthome.home.listHomeSn";
        String result = appClient.getSmallHttp().requestGet(method,null,appClient.getToken());
    }

}
